﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MVC4Shop.Models;
using System.Data.SqlClient;




namespace MVC4Shop.dao
{
    public class SizeDAO
    {
        public static List<SizeModel> GetAll()
        {
            return Convert( DataUtil.executeStore("sp_Size_GetAll", null));
        }

        public static Boolean Insert(SizeModel _model)
        {
            SqlParameter[] param = new SqlParameter[1];
            int i = 0;
            param[i] = new SqlParameter("@name", SqlDbType.NVarChar);
            param[i++].Value = _model.name;
            return DataUtil.executeNonStore("sp_Size_Insert", param);
        }

        public static Boolean Delete(String id )
        {
            SqlParameter[] param = new SqlParameter[1];
            int i = 0;
            param[i] = new SqlParameter("@id", SqlDbType.NVarChar);
            param[i++].Value = id;
            return DataUtil.executeNonStore("sp_Size_Delete", param);
        }

        public static Boolean Edit(SizeModel model)
        {
            SqlParameter[] param = new SqlParameter[2];
            int i = 0;
            param[i] = new SqlParameter("@id", SqlDbType.NVarChar);
            param[i++].Value = model.id;
            param[i] = new SqlParameter("@name", SqlDbType.NVarChar);
            param[i++].Value = model.name;
            return DataUtil.executeNonStore("sp_Size_Edit", param);
        }

        public static List<SizeModel> Convert(DataTable dt)
        {
            List<SizeModel> list = new List<SizeModel>();
            SizeModel model ;
            foreach (DataRow row in dt.Rows)
            {
                model = new SizeModel();
                model.id = row["size_id"].ToString();
                model.name = row["name"].ToString();
                list.Add(model);
            }
            return list;
        }
    }
}